<template>
	<view class="kind">
		<view class="originality block" v-if="categoryList.length" @tap="handleBlockClick(0)">
			<text class="title">{{ categoryList[0].name }}</text>
			<image :src="categoryList[0].icon" mode=""></image>
		</view>
		<view class="styles block" v-if="categoryList.length" @tap="handleBlockClick(1)">
			<text class="title">{{ categoryList[1].name }}</text>
			<image :src="categoryList[1].icon" mode=""></image>
		</view>
		<view class="other">
			<view class="other-block" v-if="categoryList.length" @tap="handleBlockClick(2)">
				<image :src="categoryList[2].icon" mode=""></image>
				<text class="title">{{ categoryList[2].name }}</text>
			</view>
			<view class="other-block" v-if="categoryList.length" @tap="handleBlockClick(3)">
				<image :src="categoryList[3].icon" mode=""></image>
				<text class="title">{{ categoryList[3].name }}</text>
			</view>
		</view>
	</view>
</template>

<script>
import { findCategory } from '../../api/home/index.js';
export default {
	data() {
		return {
			categoryList: [] // 分类列表
		};
	},
	methods: {
		async init() {
			// 获取分类
			const categoryResp = await findCategory();
			this.categoryList = categoryResp.data.category.children;
		},
		// 分类点击事件
		handleBlockClick(index) {
			console.log(index);
			const id = this.categoryList[index].id;
			uni.navigateTo({
				url: `kindlist/list?id=${id}`
			});
		}
	},
	onLoad() {
		this.init();
	}
};
</script>

<style lang="scss" scoped>
.kind {
	margin-bottom: 30rpx;
	overflow: hidden;
	.block {
		width: 670rpx;
		height: 302rpx;
		background: #d5d5d5;
		border-radius: 20rpx;
		margin: 28px auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.title {
			font-size: 48rpx;
			color: #3e3e3e;
			margin-left: 52rpx;
		}
		image {
			width: 402rpx;
			height: 100%;
			border-radius: 20rpx;
		}
	}
	.styles {
		background: #fff;
	}
	.other {
		width: 670rpx;
		height: 442rpx;
		margin: 0 auto;
		border-radius: 20rpx;
		display: flex;
		justify-content: space-between;
		&-block {
			position: relative;
			width: 312rpx;
			height: 100%;
			image {
				width: 100%;
				height: 100%;
				border-radius: 20rpx;
			}
			.title {
				position: absolute;
				left: 52px;
				top: 148rpx;
			}
		}
	}
}
</style>
